package hu.genius.model;

import hu.genius.model.entity.Product;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;


public class DBUtil {

	public static List<Product> listProductsByCategory(Context context, int categoryId) {
		DBAdapter db = new DBAdapter(context);
		db.open();
		Cursor c = db.getProductsOfCategory(categoryId);
		List<Product> products = new ArrayList<Product>();
		if (c.moveToFirst()) {
			do {
				Product product = new Product();
				product.setId(c.getInt(0));
				product.setName(c.getString(1));
				product.setPrice(c.getInt(2));
				product.setCategoryId(c.getInt(3));
				products.add(product);
			} while (c.moveToNext());
		}
		db.close();
		return products;
	}
	
//	public static List<Order> listOrders(Context context) {
//		DBAdapter db = new DBAdapter(context);
//		db.open();
//		Cursor c = db.getAllOrders();
//		List<Order> orders = new ArrayList<Order>();
//		if (c.moveToFirst()) {
//			do {
//				Order order = new Order();
//				order.setId(c.getInt(0));
//				order.setProductId(c.getInt(1));
//				order.setQuantity(c.getInt(2));
//				orders.add(order);
//			} while (c.moveToNext());
//		}
//		db.close();
//		return orders;
//	}
	
//	public static void addOrder(Context context, Product product) {
//		DBAdapter db = new DBAdapter(context);
//		db.open();
//		db.addOrder(product);
//		db.close();
//	}
	
}
